<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * wap活动地址管理
 */
class Index extends CI_Controller
{
        static $datas = array();
        public function __construct()
        {
            parent::__construct();
            self::$datas['base_url'] = config_item('base_url');
            self::$datas['base_url'] = config_item('image_url');
            $this->load->database();
            $this->load->model('common', 'common');
            $this->common->header();


        }
        // 首页
        public function index()
        {
            // 焦点新闻
           $jiao= $this->db->where('status','0')->limit('4')->get("news")->result_array();
           self::$datas['jiao']=$jiao;
           //活动新闻
           $huo=$this->db->where('status','1')->limit('8')->get("news")->result_array();
           self::$datas['huo']=$huo;
           //活动公告
           $gao=$this->db->where('status','2')->limit('8')->get("news")->result_array();
           self::$datas['gao']=$gao;
           //左上角banner1
           self::$datas['ban1']=$this->db->where('status','0')->get("banner")->result_array();
           //左上角banner2
           self::$datas['ban2']=$this->db->where('status','1')->get("banner")->result_array();
           //左上角banner3
           self::$datas['ban3']=$this->db->where('status','2')->get("banner")->result_array();
            $this->load->view('home/index',self::$datas);
            $this->common->footer();
        }
        //关于活动
        public function play()
        {
        	$part = $this->uri->segment(3);
        	if($part == 1 || $part == '')
        	{
        		$this->load->view('home/play',self::$datas);
                
        	}elseif($part == 2){

                $this->load->view('home/play_two',self::$datas);
        	}elseif($part == 3){
                $this->load->view('home/play_three',self::$datas);

        	}else{

                $this->load->view('home/play_four',self::$datas);
        	}
        	// $this->load->view('home/play',self::$datas);
            $this->common->footer();
        }
        //活动新闻
        public function news()
        {
        	//活动动态
            $part = $this->uri->segment(3);
            
            if($part == '' || $part == 1)
            {  
                self::$datas['new1']  = $this->db->limit(16)->get_where('news',array('status'=>1))->result_array();
            }elseif($part == 2){
            	self::$datas['new2']  = $this->db->limit(16)->get_where('news',array('status'=>2))->result_array();
            }elseif($part == 3){
            	//每页显示的个数
			$per_page = 5;
			if($this->uri->segment(4))
			{
			  $page = ($this->uri->segment(4) - 1) * $per_page;
			}else
			{
			  $page = 0;
			}
			self::$datas['count'] = $count = $this->db->count_all_results('news');
			$this->load->library('pagination');
			$config['per_page'] = $per_page;
			$config['base_url'] = '/index/news/3';
			$config['total_rows'] = $count;
			$config['uri_segment'] = 4;
			$config['num_links'] = 5;
			$config['use_page_numbers'] = TRUE;
			$config['full_tag_open'] = '<div>';
			$config['full_tag_close'] = '</div>';
			$config['first_link'] = '首页';
			$config['last_link'] = '末页';
			$this->pagination->initialize($config);
            self::$datas['new1']  = $this->db->limit($per_page,$page)->get_where('news',array('status'=>0))->result_array();
            self::$datas['pages'] = $this->pagination->create_links();
            }
            $this->load->view('home/new',self::$datas);
        	$this->common->footer();
        	
            
        }
        //政策通知
        public function Policy()
        {
            self::$datas['zheng']=$this->db->where('status','3')->get('news')->result_array();            
            $this->load->view('home/policy',self::$datas);
            $this->common->footer();
        }
        //普法指南
        public function law_guide()
        {
        	$part = $this->uri->segment(3);
        	if($part == 1 || $part == '')
        	{
        		$this->load->view('home/law_guide',self::$datas);
                
        	}elseif($part == 2){

                $this->load->view('home/guide_two',self::$datas);
        	}elseif($part == 3){
                $this->load->view('home/guide_three',self::$datas);

        	}else{

                $this->load->view('home/guide_four',self::$datas);
        	}
            $this->common->footer();
        }
        //站长之家
        public function site()
        {
        	$part = $this->uri->segment(3);
        	if($part == 1 || $part == '')
        	{
        		$this->load->view('home/site_one',self::$datas);
                
        	}elseif($part == 2){

                $this->load->view('home/site_two',self::$datas);
        	}elseif($part == 3){
                $this->load->view('home/site_three',self::$datas);

        	}else{

                $this->load->view('home/site_four',self::$datas);
        	}
            $this->common->footer();
        }
        //联系我们
        public function us()
        {
        	$this->load->view('home/us',self::$datas);
            $this->common->footer();
        }
         //新闻详情页
        public function newshow()
        {
            $id=$this->uri->segment(3);//新闻id
            if (!empty($id)) {
            self::$datas['show']=$this->db->where('id',$id)->get('news')->result_array();  
            $this->load->view('home/newshow',self::$datas);
            $this->common->footer();
                }
         }
         //留言
        public function mess()
        {
            $data['uname']=$this->input->post('uname',true );
            $data['tel']=$this->input->post('tel',true );
            $data['email']=$this->input->post('email',true );
            $data['qq']=$this->input->post('qq',true );
            $data['content']=$this->input->post('content',true );   
         if(!empty($data)) {   
            $in=$this->db->insert('touch',$data);
                   if ($in) {
                         echo "<script>
                                 alert('添加成功');
                                 location.href='/Index/mess';//客户端跳转
                               </script>";
                   }else{
                     echo "<script>
                                 alert('添加失败');
                               </script>";
                   }
                   exit;
                  }
               
         
            $this->load->view('home/us',self::$datas);
            $this->common->footer();
        }

}